<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form
          @submit.native.prevent
          :model="queryParams"
          ref="queryRef"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
   <!--       <el-form-item label="视频名称" prop="title">
            <el-input
              v-model="queryParams.title"
              placeholder="请输入视频名称"
              clearable
              style="width: 240px"
              @keyup.enter="handleQuery"
            />
          </el-form-item> -->
          <el-form-item label="审核状态" prop="auditStatus">
            <el-select v-model="queryParams.auditStatus" placeholder="请选择">
              <el-option
                v-for="dict in audit_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-row :gutter="10" class="mb10">
     <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport"
          >导出</el-button
        >
      </el-col> -->
      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-row class="mb8">
      <el-table
        v-loading="loading"
        :data="list"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column label="序号" width="50" align="center" type="index" />
        <el-table-column label="评论内容" align="center" prop="content" />
        <el-table-column label="审核状态" align="center" prop="audioStatus">
          <template #default="scope">
            <dict-tag :options="audit_status" :value="scope.row.auditStatus" />
          </template>
        </el-table-column>
        <el-table-column label="评论文章" align="center">
		<template #default="scope">
		    {{scope.row.article.title}}
		</template>
		</el-table-column>
		<el-table-column label="评价人" align="center">
		<template #default="scope">
		   {{scope.row.user.nickName}}
		</template>
		</el-table-column>
        <el-table-column
          label="创建时间"
          align="center"
          prop="createTime"
          width="170"
        >
          <template #default="scope">
            <span>{{ parseTime(scope.row.gmtCreate) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template #default="scope">
            <a
			 v-if="scope.row.auditStatus==0"
              href="javascript:;"
              style="color: #358de5; text-decoration: none; margin-right: 10px"
              @click="handleUpdate(scope.row)"
              >审核</a
            >
            <a
              href="javascript:;"
              style="color: #f56c6c; text-decoration: none; margin-right: 10px"
              @click="handleDelete(scope.row)"
              >删除</a
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>

    <!-- 添加或修改用户配置对话框 -->
    <el-dialog :title="title" v-model="open" width="700px" append-to-body>
      <div class="content">
      	<div class="avatar">
      		<img :src="form.article.coverImageUrl" alt="cover"  />
      	</div>
		<div class="right">
			<div class="userName">
				{{form.user.nickName || "--"}}
			</div>
			<div class="info">
				{{'发布于'+form.article.gmtCreate + '- 类型: 评论'}}
			</div>
			<div class="obj">{{"评论于文章: 《"+form.article.title+"》"}}</div>
		</div>
      </div>
	  <div class="comment">
		 {{form.content}}  
	  </div>
      <template #footer v-if="title !== '详情'">
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">通过</el-button>
          <el-button type="warning" @click="cancel">拒绝</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
  <script setup name="video">
import { ref } from "vue";
import {
  queryCommentPage,
  commentEdit,
  deleteComment
} from "@/api/comment";
const { proxy } = getCurrentInstance();
const { audit_status} = proxy.useDict("audit_status");
const list = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const title = ref("");
const ids = ref([]);
const form=ref({})
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 1000,
    title: undefined,
    auditStatus: undefined,
  },
 
});

const { queryParams } = toRefs(data);
/** 查询用户列表 */
const getList = () => {
  loading.value = true;
  queryCommentPage(queryParams.value).then(
    (res) => {
      loading.value = false;
      list.value = res.rows;
      total.value = Number(res.total);
    }
  );
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
  proxy.resetForm("queryRef");
  queryParams.value = {
    pageNum: 1,
    pageSize: 1000,
    auditStatus: undefined,
  };
  handleQuery();
};



/** 导出按钮操作 */
const handleExport = async () => {
  proxy.$modal.loading("文件导出中，请稍候...");
  let result = await videoExport();
  const blob = new Blob([result]);
  let link = document.createElement("a");
  link.href = URL.createObjectURL(blob);
  link.download = "书籍列表_" + new Date().getTime() + ".xlsx";
  link.click();
  proxy.$modal.closeLoading();
};

/** 重置操作表单 */
const reset = () => {
  form.value = {};
  proxy.resetForm("userRef");
};

const handleAdd = () => {
  title.value = "新增";
  reset();
  open.value = true;
};
/** 取消按钮 */
const cancel = () => {
	form.value.auditStatus=2
 if (form.value.id) {
   commentEdit({
	  auditStatus:2,
	   id:form.value.id
   }).then((response) => {
     proxy.$modal.msgSuccess("拒绝成功");
     open.value = false;
     getList();
   });
 }
};

/** 删除按钮操作 */
const handleDelete = (row) => {
  proxy.$modal
    .confirm("是否确认要删除" + row.title + "视频")
    .then(() => {
      return deleteComment(row.id);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("删除成功");
    })
    .catch(() => {});
};
/** 修改按钮操作 */
const handleUpdate = (row) => {
  reset();
  title.value = "审核";
  form.value = row
  open.value = true;
};

/** 提交按钮 */
const submitForm = () => {
  if (form.value.id) {
    commentEdit({
		auditStatus:1,
		id:form.value.id
	}).then((response) => {
      proxy.$modal.msgSuccess("通过");
      open.value = false;
      getList();
    });
  }
};

getList();
</script>
 <style lang='scss' scoped>
		.content{
			padding:20px 15px;
			display: flex;
			gap: 20px;
			align-items: center;
			.avatar{
				width: 80px !important;
				height: 80px !important;
			    border-radius: 50%;
				border: 1px solid #eee;
				overflow: hidden;
				img{
					width: 100%;
					height: 100%;
				}
			}
			.right{
				.userName{
					font-weight: 500;
					color:#333;
					font-size: 20px;
				}
				.info{
					color:#666;
					font-size: 16px;
					line-height: 20px;
				}
				.obj{
					color:#666;
					font-size: 16px;
					line-height: 20px;
				}
			}
		}	 
		 .comment{
			 padding:20px 15px;
			 color:#666;
			 font-size: 16px;
			 line-height: 20px;
		 }
</style>
          